<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="copyright" content="www.apicloud.com" />
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
<title>舆情工作平台登陆</title>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/login.js"></script>
<script type="text/javascript" src="./script/jquery.md5.js"></script>
<script type="text/javascript" src="./script/jquery.min.js"></script>
</head>
<body>
</body>
<script type="text/javascript">
   apiready = function() {
   /*************登陆页面子窗口***********************/
            api.openFrame({
				name: 'indexLogin',
				url: "./indexLogin.html",
				bounces: false,
				vScrollBarEnabled:false,
				hScrollBarEnabled:false,
				reload: true
			 });
   /*************登陆页面子窗口***********************/
   /*************极光推送***********************/
			 //绑定用户别名
			 var ajpush = api.require('ajpush');
			 var deviceId = faultylabs.MD5(api.deviceId);
			     deviceId = deviceId.toLowerCase();//将字符串大写转成小写
			 var param = {alias:deviceId};
			 ajpush.bindAliasAndTags(param,function(ret) {
				  var statusCode = ret.statusCode;
			 });
			 //初始化推送服务
			 ajpush.init(function(ret, err){ });

			 //Android点击消息
			 if (api.systemType =="android"){
				  /*消息/通知点击时触发（android）*/
				api.addEventListener({name:'appintent'}, function(ret,err) {
					if(ret && ret.appParam.ajpush){
						var ajpushMsg = ret.appParam.ajpush;
						var id = ajpushMsg.id;
						var title = ajpushMsg.content;
						var content = ajpushMsg.content;
						var extra = ajpushMsg.extra;
						gotoNewsDetailFun_Push(extra);
					}
				});
			 }

			 //ios点击消息
			 if (api.systemType =="ios"){
					/*在iOS平台，当应用在后台时，使用极光推送发送通知时（消息只有应用在前台才能收到），系统会往设备发送通知。
					当通知被点击后，若应用已启动，则通过上面的setListener回调给开发者；若应用未启动，APICloud会将本次推送的内容通过事件监听回调的方式交给开发者*/
					api.addEventListener({name:'noticeclicked'}, function(ret,err) {
						if(ret && ret.value){
							var ajpushMsg = ret.value;
							var content = ajpushMsg.content;
							var extra = ajpushMsg.extras;
							gotoNewsDetailFun_Push(extra);
						}
					});
			  }

			 //设置监听事件
			 api.addEventListener({name:'pause'}, function(ret,err) {
				 onResume();//监听应用进入后台，通知jpush暂停事件
			 })
			 api.addEventListener({name:'resume'}, function(ret,err) {
				 onResume();//监听应用恢复到前台，通知jpush恢复事件
			 })
        /*************极光推送***********************/
        // 设置ios7的标题栏字体变亮，全局用一个就行了
        api.setStatusBarStyle({
          style: 'dark'
        });
    }


    function onResume(){
       ajpush.onResume();
       console.log('JPush onResume');
    }

     /* 打开新闻详细 */
    function gotoNewsDetailFun_Push(extra) {
           if (api.systemType =="android"){
    	          var msg=eval("("+extra+")");
    	          var message_id = msg.news_id;
    	   }
    	   if (api.systemType =="ios"){
    	          var message_id = extra.news_id;
    	   }

 	       api.openWin({
				name: 'detailWin',
				url: "./html/detailWin.html",
				pageParam: {
					message_id: message_id
				},
				bounces: false,
				vScrollBarEnabled:false,
				hScrollBarEnabled:false,
				reload: true
		  });
    }
</script>
</html>
